using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace studentwork
{
    class Savings
    {
        int RemainingSum = 20000;
        Credit x;   //信用
        public Savings(Credit x)
        {
            this.x = x;
        }
        public void DeductMoney()   //扣款
        {
            if (x.CheckPayment() == 1)
            {
                RemainingSum = RemainingSum - x.GetAmountPending();
                Console.WriteLine("还款成功，余额为:{0}", RemainingSum);
            }
            else
            {
                Console.WriteLine("不需要还款，余额为:{0}", RemainingSum);
            }
        }
    }

    class Credit
    {
        int DueDate = 29;
        int AmountPending;
        int DateOfRepayment;
        public Credit(int RepaymentAmount, int RepaymentDate)
        {
            this.AmountPending = RepaymentAmount;
            this.DateOfRepayment = RepaymentDate;
        }
        public int GetAmountPending()
        {
            return AmountPending;
        }
        public int CheckPayment()
        {
            if (DueDate == DateOfRepayment)
                return 1;
            else
                return 0;
        }
    }
    class Delegate
    {
        public delegate void pay();
        public event pay payment;
        public void Notify()
        {
            if (payment != null)
            {
                Console.WriteLine("触发事件：");
                payment();
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Delegate objDelegate = new Delegate();
            Credit a1 = new Credit(1000, 27);
            Credit a2 = new Credit(1000, 29);
            Savings b1 = new Savings(a1);
            Savings b2 = new Savings(a2);
            objDelegate.payment +=
                new Delegate.pay(b1.DeductMoney);
            objDelegate.payment +=
               new Delegate.pay(b2.DeductMoney);
            objDelegate.Notify();
            Console.ReadLine();
        }
    }
}